package com.hitqz.robot.driver.zmq.protocol.handler;


import cn.hutool.core.util.StrUtil;
import com.hitqz.robot.driver.util.WheelToolkit;
import lombok.extern.slf4j.Slf4j;
import navconnector.NavconnectorBase;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;

/**
 * SimpleReply数据对象处理类
 *
 * @author wengyx
 * @date 2021-09-15 8:34
 **/
@Slf4j
@Component
public class SimpleReplyHandler implements HandlerZMQService {

    @Override
    public void handlerMsg(String robotSn, byte[] data) throws Exception {
        NavconnectorBase.SimpleReply simpleReply = NavconnectorBase.SimpleReply.parseFrom(data);
        int ackId = simpleReply.getHeader().getAck();
        String type = simpleReply.getDescriptorForType().getName();
        int objId = simpleReply.getHeader().getObj();
        int code = simpleReply.getCode();
        if (code!=0) {
            String message = simpleReply.getMessage();
            log.warn("[wheel]seq:{} message:{}.{} error:{}",ackId,type,objId,message);
            //释放锁
            WheelToolkit.release(ackId,type, objId, false);
            return;
        }
        //释放锁
        WheelToolkit.release(ackId,type, objId, true);
    }


}
